﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DemoBrick
{
    public partial class Frmmain : Form
    {
        private Game game;
        public Frmmain()
        {
            InitializeComponent();
        }

        private void Frmmain1_Load(object sender, EventArgs e)
        {
        }

        private void gameArea_Load(object sender, EventArgs e)
        {
            //初始化
            game = new Game();
            game.gameChanged += Game_gameChanged;
        }
        public void Game_gameChanged()
        {
            if (game != null)
            {  
                gameArea.Invalidate();
            }
}
           
    private void gameArea_Paint(object sender, PaintEventArgs e)
        {
            if (game != null)
            {
                game.Draw(e.Graphics, this.gameArea.Size);
            }

        }

        private void Frmmain_KeyDown(object sender, KeyEventArgs e)
        {
            if (game != null)
            {
                //传递按键值给game
                game.KeyDown (e.KeyCode.ToString());
                gameArea.Invalidate();
            }
        }

        private void panelRight_Paint(object sender, PaintEventArgs e)
        {

        }
    }
}
